/**
 * 商品列表页面 product.php
 */


<!--用户权限的判断逆函数-->


<!--一全选/全不选函数-->
function selectAll(obj,ck)
{
	
     var elems=obj.form.getElementsByTagName("input");
	 for (var i=0; i < elems.length; i++)
      {
        if (elems[i].name == ck || elems[i].name == ck + "[]")
          {
             elems[i].checked = obj.checked;
         }
      }
	}
<!-- 商品上架状态改变函数-->
var xml1;
var obj;
function is_on_sale(obj,id)
{
	//alert(id);
	//alert(obj.src);
	//var obj=document.getElementById("onsale")
    var val=(obj.src.match(/yes.gif/i))?0:1;
    //alert(val);
    xml1=new ActiveXObject("Msxml2.xmlhttp.3.0");
	xml1.open("GET","ajax/onsale.php?val="+val+ "&id=" +id,true);
	xml1.onreadystatechange=callback;
	xml1.send(null);
	
	function callback()
	{
		if(xml1.readystate==4)
        {
			var result=xml1.responseText;
			//alert(result);
			//alert(obj.src);
			//obj.src = (result > 0) ? 'image/yes.gif' : 'image/no.gif';
			if(result==0)
				{
				obj.src ='image/no.gif';
				}
			else if(result==1)
			{
			obj.src ='image/yes.gif';
			}
			else  if(result==2)
			 {
				history.go(0);alert('你没有上下架商品的权限');
			 }
			else
				{
			    parent.location.href('index.php');
				}
        }
    }
}
//else if(result=='2')
//{
	//history.go(-1);alert('你没有上下架商品的权限');
	//}


<!-- 删除单件商品函数-->
var xml2;
function remove(id)
{
   if(confirm('你确定要删除该商品？'))
   {
	   xml2=new ActiveXObject("Msxml2.xmlhttp.3.0");
		xml2.open("GET","ajax/remove.php?id="+id,true);
		xml2.onreadystatechange=removeCallBack;
		xml2.send(null);
	   }
  }
	function removeCallBack()
	{
		if(xml2.readystate==4)
        {
			var result=xml2.responseText;
			alert(result);
			history.go(0)
			//location.href('product.php');
        }
	}
	
	
	<!--表单提交批处理事件-->
	function confirmDel(frm)
	{
		//alert(frm.elements['type'].value );
		//var val=document.getElementById("selAction");
	      var checked=document.getElementsByName("checkboxes[]")
	     // alert(checked.length);
	      
	     for(var i=0;i<checked.length;i++)
	     {
	         var flag=0;
	      if(checked[i].checked)
	      {
	    	  flag=1;
	    	  break;
	      }
	     }
	     if(flag==0)
	     {
	    	
	   	  alert('您没有选择任何商品');
	         return false;
	     }
	     else{
	    	 if(frm.elements['type'].value=='del')
	    		 {
	    	     if (confirm('你确定删除所选商品吗？'))
	    	        return confirm(del);
	    	     else return false;
	    		 }
	    	 else if (frm.elements['type'].value =='not_on_sale')
	         {
	    		 if (confirm('你确定下架所选商品吗？'))
	             return confirm(no_on_sale);
	    		 else
	    			 return false;
	         }
	    	 else if (frm.elements['type'].value =='on_sale')
	         {
	    		 if (confirm('是否将选中的商品全部上架？'))
	             return confirm(on_sale);
	    		 else
	    			 return false;
	         }
	    	 else if (frm.elements['type'].value =='')
	         {
	             return false;
	         }
	         else
	         {
	             return true;
	         }


	     }
	    /* else if (confirm('你确定对所选商品进行这样的操作吗？'))
		  {
	    	 return confirm(drop);
	  	   //return true;
		  }
	     else 
	         return false;*/
	      
	}
		
		
	<!--三级联动类型显示函数-->
    var xml3;
    function gettid(tid)
	{
		var tid=tid;
		if(tid!=-1){
		xml3=new ActiveXObject("Msxml2.xmlhttp.3.0");
		xml3.open("GET","ajax/changetid.php?tid="+tid,true);
		xml3.onreadystatechange=panduan;
		xml3.send(null);
		}
	}
		function panduan()
		{
			var twotype=document.getElementById("twotype");
			if(xml3.readystate==4)
           {
			   var result=xml3.responseText;
			  //alert(result);
			  var secondtype= result.split(",");
			  //alert(secondtype);
			 var count=secondtype.length;
			  //alert(secondtype.split(">"));
			  //alert(count);
			  twotype.length=1;
			  for(var i=0;i<count-1;i++)
			  {
				 var tarr=secondtype[i].split(">"); 
                twotype .options.add(new Option(tarr[1],tarr[0]))
			  }
           }
	   }
			
		<!--三级分类————>
		var xml4;
		function getgid(gid)
		{
			var gid=gid;
			//alert(pid);
			xml4=new ActiveXObject("Msxml2.xmlhttp.3.0");
		xml4.open("GET","ajax/changegid.php?gid="+gid,true);
		xml4.onreadystatechange=pan;
		xml4.send(null);
			}
    function pan()
		{
			var threetype=document.getElementById("threetype");
			if(xml4.readystate==4)
           {
			   var result=xml4.responseText;
			  //alert(result);
			  var type= result.split(",");
			  //alert(secondtype);
			 var count=type.length;
			  //alert(secondtype.split(">"));
			  //alert(count);
			  threetype.length=1;
			  for(var i=0;i<count-1;i++)
			  {
				  var parr=type[i].split(">")
                threetype .options.add(new Option(parr[1],parr[0]))
			  }
           }
		}
		
		<!--颜色选择框的增删-->
function addcol()
{
　　var cell=document.getElementById("color_table").rows[0].insertCell(1);
　　cell.innerHTML=document.getElementById("color_table").rows.item(0).cells[0].innerHTML;
if(document.getElementById("color_table").rows.item(0).cells.length>1)
{
	document.getElementById("delcolor").disabled="";
	}
	if(document.getElementById("color_table").rows.item(0).cells.length>5)
	{
		document.getElementById("more").disabled="disabled";
		}
}
function removeCell()
{
　　　　document.getElementById("color_table").rows[0].deleteCell(document.getElementById("color_table").rows.item(0).cells.length-1);
if(document.getElementById("color_table").rows.item(0).cells.length==1)
{
	document.getElementById("delcolor").disabled="disabled";
	}
	if(document.getElementById("color_table").rows.item(0).cells.length<=5)
	{
		document.getElementById("more").disabled="";
		}
	
}


<!--商品尺寸的增删-->

function addSize()
{
　　var cell=document.getElementById("size_table").rows[0].insertCell(1);
　　cell.innerHTML=document.getElementById("size_table").rows.item(0).cells[0].innerHTML;
 if(document.getElementById("size_table").rows.item(0).cells.length>1)
  {
	document.getElementById("delsize").disabled="";
  }
	if(document.getElementById("size_table").rows.item(0).cells.length>3)
	{
		document.getElementById("moresize").disabled="disabled";
	}
	
}
function removeSize()
{
　　　　document.getElementById("size_table").rows[0].deleteCell(document.getElementById("size_table").rows.item(0).cells.length-1);
if(document.getElementById("size_table").rows.item(0).cells.length==1)
{
	document.getElementById("delsize").disabled="disabled";
	}
	if(document.getElementById("size_table").rows.item(0).cells.length<=3)
	{
		document.getElementById("moresize").disabled="";
	}
	
}
    <!-- 批量上传商品图片函数-->
    
    function addrow()
    {
      var table=document.getElementById("upimg_table");
      var oldrow=table.rows[0];
      var newrow=table.insertRow();

      for(var i=0;i<oldrow.cells.length;i++)
      {
           var cell=newrow.insertCell();

           cell.innerHTML=oldrow.cells[i].innerHTML;
      }

      if(table.rows.length>1)
      {
          for(var i=0;i<table.rows.length;i++)
          {
             table.rows[i].cells[1].childNodes[0].disabled="";
          
          }

      }
  	 if(table.rows.length>=5)
      {
          document.getElementById("upload").disabled="disabled";
      }
      
    }
    function delrow(obj)
    {
  	  var tr= obj.parentNode.parentNode;

  	  var table=document.getElementById("upimg_table");

  	  table.deleteRow(tr.rowIndex);

  	  if(table.rows.length==1)
  	  {
             table.rows[0].cells[1].childNodes[0].disabled='disabled';
  	  }
    }

    
    <!--添加商品表单提交函数>
    type_flag=false;
    name_falg=false;
    sn_flag=false;
    price_flag=false;
    function checksubmit()
    {
    	checkType();
    	checkName('good_name');
    	checknum('good_sn');
    	check_isNum('ueprice');
    	check_isNum('market_price');
    	if(type_flag&&name_flag&&sn_flag&&price_flag)
    	   {
    		   return true;
    		   }
    	   else 
    		{
    			//alert(type_flag)
    			return false;
    			}
    	}
     function checkType()
     {
    	 if(document.getElementById("threetype").value>0)
    	   {
    		   type_flag=true;
    		   }
    	   else
    	   {
    		   //alert('请选择商品类型');
    		   type_flag=false;
    		   document.getElementById("bigtype").focus();
    		   }
    	 }
    var good_name_span;
    function checkName(val)
    {
    	//var name=val;
    	var name=document.getElementById(val).value;
    	var good_name_span=document.getElementById("good_name_span"); 
        	//alert (val);
    	var reg=/^[\u4e00-\u9fa50-9A-Za-z]{2,40}$/;
    	//var reg = /^[a-zA-Z\d]\w{3,11}[a-zA-Z\d]$/;
    	 
    	if(name=="")
    	{
    		 good_name_span.innerHTML="商品名称不能为空"
    			 document.getElementById(val).focus();
    			 name_flag= false;
    		}
    	else
    	{
    		if(reg.test(name)){
    			good_name_span.innerHTML="允许使用";
    			name_flag=true;
    			}
    		else{
    				good_name_span.innerHTML="不允许使用";
    				document.getElementById(val).focus();
    				name_flag=false;
    			}
    	}
         
      }
    
    <!-- 货号检查-->
    	 var xml5;
    function checknum(val)
    {
    	var good_sn=document.getElementById(val).value;
    	//alert (good_sn);
    	var good_sn_span=document.getElementById("good_sn_span"); 
       xml5=new ActiveXObject("Msxml2.xmlhttp.3.0");
       	xml5.open("GET","ajax/check_good_sn.php?num="+good_sn,true);
       	xml5.onreadystatechange=good_snCall;
       	xml5.send(null);
        	
    }
       	
       	function good_snCall()
       	{
       		//alert('ggg')
       		if(xml5.readystate==4)
               {
       			var good_sn_span=document.getElementById("good_sn_span");
       			   var result=xmlH.responseText;
       			   good_sn_span.innerHTML=result;
       			   if(result=="可以使用该货号")
       			   {
       				  sn_flag=true;
       			   }
       			   else
       			   {
       				   //alert('请检查商品货号');
       				//document.getElementById("good_sn").focus();
       				   sn_flag=false;
       			   }
               }
            }
       	
       	<!-- 价格检查-->
function check_isNum(val)
{
	//alert(val);
	var isNum=document.getElementById(val).value;
	 var ueprice_span=document.getElementById("ueprice_span");
	 var market_price_span=document.getElementById("market_price_span");
	 var reg=/^[0-9]+$/;
	 if(isNum!="")
		 {
		 if(!reg.test(isNum))
			 {
			 if(val=="ueprice")
				 {
			 ueprice_span.innerHTML="<font color='red' size='2'>  格式不正确</font>";
			 price_flag=false;
			 isNum=document.getElementById(val).focus();
				 }
			 if(val=="market_price")
				 {
				 market_price_span.innerHTML="<font color='red' size='2'>  格式不正确</font>";
				 price_flag=false;
				 isNum=document.getElementById(val).focus();
				 }
			 }
		 else {
			 price_flag=true;
		      }
		 }
	 else
		 {
		 price_flag=true;
		 }
}
<!-- 编辑商品页面表单提交-->


<!--添加商品类型-->
function showTypeAdd()
{
    var show=document.getElementById("type_add");
    if(show.style.display=="none")
        show.style.display="";
    else
        show.style.display="none";
    }
var xml;
function addType(gid)
{
    //var name=document.getElementById("addTypeName").value;
   // alert(gid);
    name=encodeURIComponent(document.getElementById("addTypeName").value);
	 xml=new ActiveXObject("Msxml2.xmlhttp.3.0");
		xml.open("GET","ajax/addtype.php?name="+name+"&id="+gid,true);
		xml.onreadystatechange=function(){
			if(xml.readystate==4)
	    {
			   var result=xml.responseText;
			   if(result==0)
				{
				document.getElementById("call_span").innerHTML="该类型已存在";
				}
			else if(result==1)
			{
			document.getElementById("call_span").innerHTML="添加类型失败";
			}
			else if(result==2)
			{
				alert('类型名称不能为空');
			}
			else
				{
	   var tname=result.split(">");
			//alert(bid[0]);
	  //document.getElementById("callbrand_span").innerHTML=result;
	  var selBrand = document.forms['theform'].elements['threeTname'];
     var opt = document.createElement("OPTION");
     opt.value =tname[0];
     opt.selected = true;
     opt.text =tname[1];
     selBrand.add(opt);
				}	  
		 }
			
	  }
		xml.send(null);
    }


<!--添加商品品牌-->

function showBrandAdd()
{
    var show=document.getElementById("brand_add");
    if(show.style.display=="none")
        show.style.display="";
    else
        show.style.display="none";
    }
var xmlbrand;
function addBrand()
{
    //var name=document.getElementById("addTypeName").value;
   // alert(gid);
    name=encodeURIComponent(document.getElementById("addedBrandName").value);
   name=name.replace(/^\s+|\s+$/g, '');
    xml=new ActiveXObject("Msxml2.xmlhttp.3.0");
		xml.open("GET","ajax/addBrand.php?name="+name,true);
		xml.onreadystatechange=function(){
			if(xml.readystate==4)
	    { 
				var result=xml.responseText;
				//alert(result);
				if(result==0)
					{
					document.getElementById("callbrand_span").innerHTML="该品牌已存在";
					}
				else if(result==1)
				{
					//alert('添加品牌失败');
				document.getElementById("callbrand_span").innerHTML="添加品牌失败";
				}
				else if(result==2)
				{
					alert('品牌名称不能为空');
				}
				else
					{
		   var bid=result.split(">");
				//alert(bid[0]);
		  //document.getElementById("callbrand_span").innerHTML=result;
		  var selBrand = document.forms['theform'].elements['brand_id'];
	      var opt = document.createElement("OPTION");
	      opt.value =bid[0];
	      opt.selected = true;
	      opt.text =bid[1];
	      selBrand.add(opt);
					}
	  }
	}
					xml.send(null);
  }


<!--检查货号-->
var xmlH;
var good_sn_span;
function checknum(val)
{
var good_sn=document.getElementById(val).value;
var good_sn_span=document.getElementById("good_sn_span"); 
//alert (good_sn);
xmlH=new ActiveXObject("Msxml2.xmlhttp.3.0");
xmlH.open("GET","ajax/check_good_sn.php?num="+good_sn,true);
xmlH.onreadystatechange=good_snCall;
xmlH.send(null);
}

function good_snCall()
{
	//alert('ggg')
	if(xmlH.readystate==4)
  {
		var good_sn_span=document.getElementById("good_sn_span");
		   var result=xmlH.responseText;
		   good_sn_span.innerHTML=result;
		   if(result=="可以使用该货号")
		   {
			  sn_flag=true;
		   }
		   else
		   {
			   sn_flag=false;
		   }
  }
}
function checkEdit()
{
checkName('good_name');
if(name_flag)
{
  return true;
  }
else 
{
	//alert(type_flag)
	return false;
	}
}


<!--删除二级分类函数-->

var xmlg;
function delgtype(id)
{
   if(confirm('你确定要删除该商品类型？'))
   {
	   xmlg=new ActiveXObject("Msxml2.xmlhttp.3.0");
		xmlg.open("GET","ajax/delgtype.php?id="+id,true);
		xmlg.onreadystatechange=function(){
			
			if(xmlg.readystate==4)
	        {
				var result=xmlg.responseText;
				alert(result);
				history.go(0)
				//location.href('product.php');
	        }
		}
		
	}
		xmlg.send(null);
}

<!--删除最小分类-->
var xmlp;
function removeptype(id)
{
   if(confirm('你确定要删除该商品类型？'))
   {
	   xmlp=new ActiveXObject("Msxml2.xmlhttp.3.0");
		xmlp.open("GET","ajax/removeptype.php?id="+id,true);
		xmlp.onreadystatechange=function(){
			
			if(xmlp.readystate==4)
	        {
				var result=xmlp.responseText;
				alert(result);
				history.go(0)
				//location.href('product.php');
	        }
		}
		
	}
		xmlp.send(null);
}
<!--删除管理员函数-->
function adminremove(id)
{
	if(confirm('你确定要把此人从管理员列表清除吗？'))
	   {
		   xmladmin=new ActiveXObject("Msxml2.xmlhttp.3.0");
			xmladmin.open("GET","ajax/removeadmin.php?id="+id,true);
			xmladmin.onreadystatechange=function(){
				
				if(xmladmin.readystate==4)
		        {
					var result=xmladmin.responseText;
					alert(result);
					history.go(0)
					//location.href('product.php');
		        }
			}
			xmladmin.send(null);
		}
			
	}
<!--删除注册会员函数-->
function userremove(id)
{
	if(confirm('你确定要删除这位注册会员吗？'))
	   {
		   xmluser=new ActiveXObject("Msxml2.xmlhttp.3.0");
			xmluser.open("GET","ajax/removeuser.php?id="+id,true);
			xmluser.onreadystatechange=function(){
				
				if(xmluser.readystate==4)
		        {
					var result=xmluser.responseText;
					alert(result);
					history.go(0)
					//location.href('product.php');
		        }
			}
			xmluser.send(null);
		}
			
	}
<!--删除订单函数-->
function removethis(value,id)
{
	//alert(value);
	if(value==3)
		{
		alert('该笔订单已经付款 还未发货 你不能删除')
		}
	else if(value!=1)
    {
	    if(confirm('该笔订单还未完成，你确定要删除吗？'))
	   {
		   xmlorder=new ActiveXObject("Msxml2.xmlhttp.3.0");
			xmlorder.open("GET","ajax/removeorder.php?id="+id+"&val="+value,true);
			xmlorder.onreadystatechange=function(){
				
				if(xmlorder.readystate==4)
		        {
					var result=xmlorder.responseText;
					alert(result);
					history.go(0)
					//location.href('product.php');
		        }
			}
			xmlorder.send(null);
		}
	}	
	else{
		 if(confirm('你确定要删除该笔订单吗？'))
		   {
			   xmlorder=new ActiveXObject("Msxml2.xmlhttp.3.0");
				xmlorder.open("GET","ajax/removeorder.php?id="+id+"&val="+value,true);
				xmlorder.onreadystatechange=function(){
					
					if(xmlorder.readystate==4)
			        {
						var result=xmlorder.responseText;
						alert(result);
						history.go(0)
						//location.href('product.php');
			        }
				}
				xmlorder.send(null);
			}
	}
}
